<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-row :gutter="20">
        <el-col :span="24" align="right">
          <el-form-item label="选取领料时间范围" prop="ksCode" label-width="130px">
            <el-date-picker
              v-model="dateRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="领料单号" prop="llCode">
            <el-input
              v-model="queryParams.lldh"
              placeholder="请输入来料批次"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['warehouse:llrk:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scllMaterialRequiredRescord" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="55">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="领料单号" align="center" prop="scllProductionMaterialRequisition.lldh" />
      <el-table-column label="物料名称" align="center" prop="wldaMaterialFile.wlName" />
      <el-table-column label="物料分类" align="center" prop="wldaMaterialFile.wlSortcode," >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wl_sortcode" :value="scope.row.wldaMaterialFile.wlSortcode"/>
        </template>
      </el-table-column>
      <el-table-column label="物料规格" align="center" prop="wldaMaterialFile.wlGg" />
      <el-table-column label="物料单位" align="center" prop="wldaMaterialFile.jldwMeasurementUnit.dwName" />
      <el-table-column label="生产工单号" align="center" prop="scllProductionMaterialRequisition.scgdProductionWorkOrder.gdCode" />
      <el-table-column label="产品名称" align="center" prop="scllProductionMaterialRequisition.scgdProductionWorkOrder.cpProduct.cpName" />
      <el-table-column label="产品型号" align="center" prop="scllProductionMaterialRequisition.scgdProductionWorkOrder.cpProduct.cpType" />
      <el-table-column label="消耗数量" align="center" prop="getNum" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {listLltj} from "@/api/statistical/lltj";


export default {
  // 路由地址=name
  // 组件路径=statistical/cltj/index.vue
  // 权限=statistical:cltj:list
  name: "lltj",
  dicts: ['wl_type', 'wl_sortcode'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedWldaMaterialFile: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 来料入库表格数据
      llrkList: [],
      // 客商档案表格数据
      bgdWorkOrderForm: [],
      // 领料统计数据
      scllMaterialRequiredRescord:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lldh: null,
        dateMap: null // 用于存储选取的时间范围
      },
      dateRange:[]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询来料入库列表 */
    getList() {
      this.reset();
      this.loading = true;
      if (this.dateRange.length === 2) {
        let startTime = this.dateRange[0];
        let endTime = this.dateRange[1];

        this.queryParams.dateMap = {
          "startTime": startTime,
          "endTime": endTime
        };
      }
      listLltj(this.queryParams).then(response => {
        this.scllMaterialRequiredRescord = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        isUse: null,
        isDelete: null,
        wldaMaterialFile: {
          wlName:null,
          wlCode:null
        },
        ksMerchants:{
          ksCode:null,
          merchantsName:null
        }
      };
      this.wldaMaterialFileList = [];
      this.value=null;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.llCode)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 复选框选中数据 */
    handleWldaMaterialFileSelectionChange(selection) {
      this.checkedWldaMaterialFile = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('warehouse/llrk/export', {
        ...this.queryParams
      }, `llrk_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
